﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TAR4_Lib.Restaurant.Delivery;

namespace TAR4_Lib.Restaurant
{
    /// <summary>
    /// Initializes a new instance of the <see cref="T:System.Object"/> class.
    /// </summary>
    public class Product
    {
        private Product(int productID, string name, string shortName, Decimal price, DeliverySite associatedDeliverySite, string productCode, bool isLimited, int sizePercentage, string imageRelativePath)
        {
            this.ProductID = productID;
            this.Name = name;
            this.ShortName = shortName;
            this.Price = price;
            this.AssociatedDeliverySite = associatedDeliverySite;
            this.ProductCode = productCode;
            this.IsLimited = isLimited;
            this.SizePercentage = sizePercentage;
            this.ImageRelativePath = imageRelativePath;
        }

        public int ProductID { get; protected set; }
        public string Name { get; protected set; }
        public string ShortName { get; protected set; }
        public Decimal Price { get; set; }
        public DeliverySite AssociatedDeliverySite { get; protected set; }
        public string ProductCode { get; protected set; }
        public bool IsLimited { get; protected set; }
        public int SizePercentage { get; protected set; }
        public string ImageRelativePath { get; protected set; }

        public ProductRunningValues GetRunningValues(DateTime startDateTime, DateTime endDateTime)
        {
            throw new NotImplementedException();
            //DettagliDisponibilitaProdotto retValue;

            //SqlConnection conn = new SqlConnection(Database.GetDBConnectionString());
            //SqlCommand cmd = new SqlCommand();
            //cmd.Connection = conn;
            //cmd.CommandText = "[Cucina].[SP_LimitiProdotto_Par]";
            //cmd.CommandType = System.Data.CommandType.StoredProcedure;
            //cmd.Parameters.Add(new SqlParameter("@ProdottoID", System.Data.SqlDbType.Int) { Value = ProdottoID });

            //cmd.Parameters.Add(new SqlParameter("@UltimoLimite", System.Data.SqlDbType.Int, 8) { Direction = System.Data.ParameterDirection.Output });
            //cmd.Parameters.Add(new SqlParameter("@TimeStampLimite", System.Data.SqlDbType.DateTime) { Direction = System.Data.ParameterDirection.Output });
            //cmd.Parameters.Add(new SqlParameter("@InCoda", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output });
            //cmd.Parameters.Add(new SqlParameter("@Locked", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output });
            //cmd.Parameters.Add(new SqlParameter("@Rimanenti", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output });

            //try
            //{
            //    conn.Open();
            //    cmd.ExecuteNonQuery();

            //    if (cmd.Parameters["@UltimoLimite"].Value == DBNull.Value)
            //    {
            //        return new DettagliDisponibilitaProdotto(
            //            null, null, null, null);
            //    }
            //    else
            //    {
            //        retValue = new DettagliDisponibilitaProdotto(
            //            (DateTime)cmd.Parameters["@TimeStampLimite"].Value,
            //            (int)cmd.Parameters["@UltimoLimite"].Value,
            //            (int)cmd.Parameters["@InCoda"].Value,
            //            (int)cmd.Parameters["@Locked"].Value);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            //finally
            //{
            //    cmd.Dispose();
            //    conn.Close();
            //    conn.Dispose();
            //}

            //return retValue;
        }

        public void SetProductLimit(int? newLimit, DateTime limitDateTime)
        {
            throw new NotImplementedException();
            //SqlConnection conn = new SqlConnection(Database.GetDBConnectionString());
            //SqlCommand cmd = new SqlCommand();
            //cmd.Connection = conn;
            //cmd.CommandText = "[Cucina].[SP_LimiteProdotto_I]";
            //cmd.CommandType = System.Data.CommandType.StoredProcedure;
            //cmd.Parameters.Add(new SqlParameter("@ProdottoID", System.Data.SqlDbType.Int) { Value = ProdottoID });
            //if (limite.HasValue)
            //{
            //    cmd.Parameters.Add(new SqlParameter("@Limite", System.Data.SqlDbType.Int) { Value = limite });
            //}
            //else
            //{
            //    cmd.Parameters.Add(new SqlParameter("@Limite", System.Data.SqlDbType.Int) { Value = DBNull.Value });
            //}
            //cmd.Parameters.Add(new SqlParameter("@TimeStamp_Insert", System.Data.SqlDbType.DateTime) { Value = dataOraLimite });

            //try
            //{
            //    conn.Open();
            //    cmd.ExecuteNonQuery();
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            //finally
            //{
            //    cmd.Dispose();
            //    conn.Close();
            //    conn.Dispose();
            //}
        }
    }
}
